<?php
/*
 * Copyright (c) 2022 西部盒子.
 * Author:  @luge
 * Update: 2022/5/20 上午9:44
 */

//添加一个PostType来记录日志
//！！！！！注册post_type一定要全局执行，否则前台无法查询
add_action('init', function () {
    global $pagenow, $wp_version;
    $labels = array(
        'name' => '日志',
        'singular_name' => '日志管理',
        'add_new' => '添加',
        'add_new_item' => '添加',
        'edit_item' => '编辑',
        'new_item' => '添加',
        'view_item' => '查看',
        'search_items' => '查找',
        'not_found' => '没有内容',
        'not_found_in_trash' => '回收站为空',
        'parent_item_colon' => ''
    );
    $args = array(
        'labels' => $labels,
        'description' => '标题 = 版本号，内容 = 更新内容',
        'public' => false,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => false,
        'map_meta_cap' => true,
        'hierarchical' => false,
        'show_in_rest' => false,
        'show_in_menu' => true,
        'has_archive' => false,
        'exclude_from_search' => false,
        'supports' => array('title', 'editor', 'categories'),
        'menu_icon' => 'dashicons-update-alt',

    );
    register_post_type('wb_log', $args);

    $is_hierarchical = $pagenow === 'edit.php' || ($pagenow === 'admin-ajax.php' && isset($_POST['action']) && $_POST['action'] === 'inline-save');
    register_taxonomy('wb_log_cat', 'wb_log',
        array(
            'labels' => array(
                'add_new_item' => '添加分类',
                'edit_item' => '编辑分类',
                'update_item' => '更新分类'
            ),
            'description' => '有多个产品时通过日志分类来区分，调用简码内不加入分类ID将直接调用所有日志',
            'public' => false,
            'show_ui' => true,
            'label' => '分类',
            'default_term' => '默认项目',
            'show_in_rest' => false,
            'meta_box_cb' => 'post_categories_meta_box',
            'hierarchical' => $is_hierarchical || version_compare($wp_version, '5.1', '<')
        )
    );
});
